package com.hefu.virtuallife.ui.map.history;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.hefu.virtuallife.R;
import com.hefu.virtuallife.base.BaseActivity;
import com.hefu.virtuallife.utils.UiUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class TaxiHistoryActivity extends BaseActivity {


    @BindView(R.id.tab)
    TabLayout tab;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    private List<TaxiHistoryListFragment> fragments;


    @Override
    protected int setLayoutId() {
        return R.layout.activity_taxi_history;
    }

    @Override
    protected void initVariables(@Nullable Bundle savedInstanceState) {
        final String[] taxiHistory = UiUtils.getStringArray(R.array.taxi_history);
        tab.setTabMode(TabLayout.MODE_FIXED);
        for (String name : taxiHistory) {
            tab.addTab(tab.newTab().setText(name));
        }
        fragments = new ArrayList<>();
        fragments.add(TaxiHistoryListFragment.newInstance("1"));
        fragments.add(TaxiHistoryListFragment.newInstance("2"));
        fragments.add(TaxiHistoryListFragment.newInstance("3"));
        fragments.add(TaxiHistoryListFragment.newInstance("4"));
        FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public int getCount() {
                return taxiHistory.length;
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return taxiHistory[position];
            }

            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }
        };
        viewPager.setOffscreenPageLimit(3);
        viewPager.setAdapter(adapter);
        tab.setupWithViewPager(viewPager);
    }

    @OnClick(R.id.img_return)
    protected void onFinishClick() {
        finish();
    }



}
